//
//  APArticlesCollectionViewCell.m
//  AqualPolo
//
//  Created by dong on 2024/5/9.
//

#import "APArticlesCollectionViewCell.h"

@implementation APArticlesCollectionViewCell

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.contentView.layer.cornerRadius = 8;
        self.contentView.layer.masksToBounds = true;
        
        _imageView = [[UIImageView alloc] init];
        _imageView.contentMode = UIViewContentModeScaleAspectFill;
        _imageView.layer.masksToBounds = true;
        [self.contentView addSubview:_imageView];
        [_imageView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.edges.equalTo(self.contentView);
        }];
        
        UIView *coverView = [[UIView alloc] init];
        coverView.userInteractionEnabled = false;
        [coverView setGradientBackgroundWithColors:@[LYRGBAColor(0, 0, 0, 0.5),LYRGBAColor(0, 0, 0, 0)] locations:@[@0,@1] startPoint:CGPointMake(0.5, 0) endPoint:CGPointMake(0.5, 1)];
        [self.contentView addSubview:coverView];
        [coverView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.edges.equalTo(self.contentView);
        }];
        
        _avatarImageView = [[UIImageView alloc] init];
        _avatarImageView.layer.cornerRadius = 14;
        _avatarImageView.layer.masksToBounds = true;
        [self.contentView addSubview:_avatarImageView];
        [_avatarImageView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.contentView).offset(8);
            make.bottom.equalTo(self.contentView).offset(-4);
            make.size.mas_equalTo(CGSizeMake(28, 28));
        }];
        
        _nameLabel = [[UILabel alloc] init];
        _nameLabel.textColor = [UIColor whiteColor];
        _nameLabel.font = [LYFont fontWithSize:12 fontName:LYFontNamepfr];
        _nameLabel.textAlignment = NSTextAlignmentLeft;
        [self.contentView addSubview:_nameLabel];
        [_nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.bottom.equalTo(_avatarImageView);
            make.left.equalTo(_avatarImageView.mas_right).offset(8);
            make.right.equalTo(self.contentView).offset(-8);
        }];
        
        _titleLabel = [[UILabel alloc] init];
        _titleLabel.textColor = [UIColor whiteColor];
        _titleLabel.font = [LYFont fontWithSize:12 fontName:LYFontNamepfr];
        _titleLabel.textAlignment = NSTextAlignmentLeft;
        [self.contentView addSubview:_titleLabel];
        [_titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.bottom.equalTo(_avatarImageView.mas_top).offset(-4);
            make.left.equalTo(self.contentView).offset(8);
            make.right.equalTo(self.contentView).offset(-8);
        }];
        
        _topButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [self.contentView addSubview:_topButton];
        [_topButton mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.contentView).offset(6);
            make.right.equalTo(self.contentView).offset(-4);
            make.size.mas_equalTo(CGSizeMake(24, 24));
        }];
    }
    return self;
}

@end
